#include<cstdio>//STD
#include<algorithm>

template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

long long int n;
long long int A_1,A_2,A_3;
long long int ans=0;

int main()
{
	read(n);
	if(n<=2)
	{
		printf("0");
		return 0;
	}
	read(A_1),read(A_2);
	for(int i=3;i<=n;++i)
	{
		read(A_3);
		if(A_1>=A_2&&A_2<=A_3)ans=ans+1;
		else if(A_1<=A_2&&A_2>=A_3)ans=ans+1;
		A_1=A_2;
		A_2=A_3;
	}
	printf("%lld",ans);
	return 0;
}
